package cn.bdqn.mapper;

import cn.bdqn.pojo.SysUser;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface SysUserMapper {
    /**
     * 新增
     * @param sysUser
     * @return
     */
    @Insert("  INSERT INTO sys_user(usr_name,usr_password,usr_role_id,usr_flag)\n" +
            "VALUES (#{usrName}, #{usrPassword}, #{usrRoleId}, #{usrFlag})")
    public int insert(SysUser sysUser);

    /**
     * 修改
     * @param sysUser
     * @return
     */
    @Update(" UPDATE sys_user\n" +
            "        <set>\n" +
            "            <if test=\"usrName!=null and usrName!=''\">\n" +
            "                usr_name = #{usrName},\n" +
            "            </if>\n" +
            "            <if test=\"usrPassword!=null and usrPassword!=''\">\n" +
            "                usr_password = #{usrPassword},\n" +
            "            </if>\n" +
            "            <if test=\"usrRoleId!=null\">\n" +
            "                usr_role_id = #{usrRoleId},\n" +
            "            </if>\n" +
            "            <if test=\"usrFlag!=null\">\n" +
            "                usr_flag = #{usrFlag},\n" +
            "            </if>\n" +
            "        </set>\n" +
            "        WHERE usr_id = #{usrId}")
    public int update(SysUser sysUser);

    /**
     * 删除
     * @param id
     * @return
     */
    @Delete(" DELETE FROM sys_user WHERE usr_id = #{usrId}")
    public int delete(Long id);

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Select("   select * from sys_user WHERE usr_id = #{id}")
    @Results({
            @Result(column = "usr_id",property = "usrId",id = true),
            @Result(column = "usr_name",property = "usrName"),
            @Result(column = "usr_password",property = "usrPassword"),
            @Result(column = "usr_role_id",property = "usrRoleId"),
            @Result(column = "usr_flag",property = "usrFlag"),
    })
    public SysUser selectById(Long id);

    /**
     * 查询所有
     * @return
     */
    @Select("select * from sys_user")
    @Results({
            @Result(column = "usr_id",property = "usrId",id = true),
            @Result(column = "usr_name",property = "usrName"),
            @Result(column = "usr_password",property = "usrPassword"),
            @Result(column = "usr_role_id",property = "usrRoleId"),
            @Result(column = "usr_flag",property = "usrFlag"),
    })
    public List<SysUser> selectList();
}
